//
//  ZYCAttendanceCourseEvaluationDetailViewController.m
//  ZDSC
//
//  Created by ZDTX on 2021/8/3.
//

#import "ZYCAttendanceCourseEvaluationDetailViewController.h"
#import "ZYCAttendanceEvaluateDetailCell.h"
#import "ZYCAttendanceEvaluateDetailHeaderView.h"
#import "ZYCAttendanceEvaluateDetailBottomView.h"
#import "ZYCTeachingEvaluatedDetailModel.h"

@interface ZYCAttendanceCourseEvaluationDetailViewController ()<UITableViewDataSource,UITableViewDelegate>

@property (nonatomic, strong) ZYCTeachingEvaluatedDetailModel *detailModel;
@property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, strong) ZYCAttendanceEvaluateDetailHeaderView *headerView;
@property (nonatomic, strong) ZYCAttendanceEvaluateDetailBottomView *bottomView;
@end

@implementation ZYCAttendanceCourseEvaluationDetailViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.title = @"评课";
    [self.view addSubview:self.tableView];
    self.tableView.tableHeaderView = self.headerView;
    self.tableView.tableFooterView = self.bottomView;
    [self loadEvaluationDetail];
}

// 评价详情
- (void)loadEvaluationDetail{
    NSDictionary *params = @{
        @"listenClassId":self.listenClassId
    };
    [MrjSVProgressHUD showWithStatus:@"加载中..."];
    [[URLManager sharedURLManager] postUrlString:Appliance_Post_TeachGetSchemaListBySaved requestService:RequestServiceWorkBench parameters:params progress:^(NSProgress * _Nonnull downloadProgress) {
            
        } success:^(id  _Nullable responseObject) {
            [MrjSVProgressHUD dismiss];
            if (SUCCESS(responseObject[@"code"])) {
                self.detailModel = [ZYCTeachingEvaluatedDetailModel yy_modelWithDictionary:responseObject[@"body"]];
                self.bottomView.titleString = self.detailModel.content;
                self.headerView.model = self.detailModel;
                [self.tableView reloadData];
            }else{
                [MrjToast makeToast:responseObject[@"message"] makeView:self.view];
            }
            
        } failure:^(NSError * _Nonnull error) {
            
        }];
}


#pragma mark - UITableViewDelegate,UITableViewDataSource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return self.detailModel.schemeProjectList.count;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 1;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    ZYCAttendanceEvaluateDetailCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([ZYCAttendanceEvaluateDetailCell class]) forIndexPath:indexPath];
    ZYCTeachingEvaluatedSingleModel *model = self.detailModel.schemeProjectList[indexPath.section];
    cell.model = model;
    return cell;
}
-(CGFloat) tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 15.0f;
}

-(CGFloat) tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return 0.01;
}


- (nullable UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
    UIView *headerView = [UIView new];
    headerView.backgroundColor = HEX_RGB(@"#F9F9F9");
    return headerView;
}

- (nullable UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    return [UIView new];
}

#pragma mark - getters

- (UITableView *)tableView {
    if (!_tableView) {
        _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, kNavBarAndStatusBarHeight, kScreenWidth, kScreenHeight - kNavBarAndStatusBarHeight) style:UITableViewStyleGrouped];
        _tableView.delegate = self;
        _tableView.dataSource = self;
        _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        [_tableView registerClass:[ZYCAttendanceEvaluateDetailCell class] forCellReuseIdentifier:NSStringFromClass([ZYCAttendanceEvaluateDetailCell class])];
        _tableView.estimatedRowHeight = 118;
        _tableView.rowHeight = UITableViewAutomaticDimension;
    }
    return _tableView;
}

- (ZYCAttendanceEvaluateDetailHeaderView *)headerView {
    if (!_headerView) {
        _headerView = [[ZYCAttendanceEvaluateDetailHeaderView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, 65.0f)];
    }
    return _headerView;
}

- (ZYCAttendanceEvaluateDetailBottomView *)bottomView {
    if (!_bottomView) {
        _bottomView = [[ZYCAttendanceEvaluateDetailBottomView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, 350)];
    }
    return _bottomView;
}


/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
